package org.numb.chapter02.common;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class ZKCliFactory {

    private static final String ZK_ADDRESS = "124.221.113.26:12181,124.221.113.26:12182,124.221.113.26:12183";

    private volatile static CuratorFramework zkCli;

    private ZKCliFactory() {

    }

    public static CuratorFramework getZKCli() {
        if (zkCli == null) {
            synchronized (ZKCliFactory.class) {
                if (zkCli == null) {
                    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000 ,3);
                    zkCli = CuratorFrameworkFactory.newClient(ZK_ADDRESS, retryPolicy);
                    return zkCli;
                }
            }
        }
        return zkCli;
    }
}
